<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <input type="button" value="打印" onclick="print()">
    <script>
        var arr_id = 0
        print_arr = (arr) => {
            console.log("arr" + (++arr_id) + ":")
            for (let i in arr) {
                console.log(arr[i])
            }
        }
        //1.创建数组
        //常规方法
        let arr1 = new Array(1, 2, 3, 4)
        print_arr(arr1)

        //字面:使用中括号
        let arr2 = [1, 2, true, "@#$"]
        print_arr(arr2)
        console.log('\n')

        //数组内置方法,支持lambda表达式
        arr2.forEach(x => console.log(x))
        console.log('\n')
        
        let arr3 = [1, 33, 44, 2, 45, 3333, 33, 22]
        console.log("默认使用编码值升序排序")
        print_arr(arr3.sort())
        console.log("\n")
        arr3.sort((a, b) => { return a - b })
        print_arr(arr3)

        //2. RegExp正则对象
        //第一种方法
        let reg1 = new RegExp("^\\d{5}$")    //'/'需要转义
        console.log(reg1.test("111"))   //false
        console.log(reg1.test("11122")) //true

        //第二种方法
        let reg2 = /^[abcde]{9}$/
        console.log(reg2.test("abcdef"))    //false
        console.log(reg2.test("abcdeabcde"))    //false
        console.log(reg2.test("abcdeabcd")) //true
        
        //创建string对象
        let str = "2222"
        let str1 = new String("哈哈哈哈")
        console.log(typeof(str))    //string
        console.log(typeof(str1))   //object
        //字符串拼接
        //1.
        let index = "中间"
        console.log(str + index + str1)
        console.log(`${str}${index}${str1}`)    //es6新语法``使用反单引号

    </script>
</body>

</html>